#include<stdio.h>
const int maxn=10010;
int main()
{
	int ans=0,n,p;
	scanf("%d%d",&n,&p);
	while(n){
		ans+=n/p;
		n/=p;
	}
	printf("%d",ans);
	return 0;
}
